package org.jeecg.modules.paycenter.channel.zzbank.task;

import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.PayConstants;
import org.jeecg.modules.paycenter.channel.zzbank.service.IHyZzbankAccountService;
import org.jeecg.modules.paycenter.enums.PayChannelEnum;
import org.jeecg.modules.wlhy.bill.entity.HyDriverBill;
import org.jeecg.modules.wlhy.bill.service.IHyDriverBillService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Configuration
@EnableScheduling
public class ZhengzhouBankDownloadReceiptTask {

    @Resource
    private IHyDriverBillService hyDriverBillService;
    @Resource
    private IHyZzbankAccountService accountService;

    @Scheduled(cron = "${scheduling.cashoutjob:-}")
    private void downloadReceipt() throws Exception {
        log.info("=====================定时任务开始下载对账单===================");
        List<HyDriverBill> inprocessList = hyDriverBillService.lambdaQuery()
                .eq(HyDriverBill::getPayChannel, PayChannelEnum.ZHENGZHOU.channelType)
                .eq(HyDriverBill::getBillType, PayConstants.BILL_TYPE.PAY_FREIGHT)
                .eq(HyDriverBill::getRespCode, PayConstants.BANK_PAY_SOUR.SUCCESS)
                .isNull(HyDriverBill::getBankReceipt)
                .list();

        if (CollUtil.isNotEmpty(inprocessList)) {
            for (HyDriverBill hyDriverBill : inprocessList) {
                accountService.downloadReceipt4Driver(hyDriverBill);
            }
        }
        log.info("=====================定时任务下载对账单结束=================");

    }
}
